<?php
namespace Admin\Controller;
use Think\Controller;
class MerchantController extends CommonController {
	
	public function _initialize(){
	parent::_initialize();
	$this->model="merchant";
	$this->key="mh_id";	
	$this->title_index= L('index');
	$this->title_details=L('details');
	}
	
	/**
	*商户列表页面，由于涉及到搜索问题，重写父类方法
	*/
	public function index(){
		$mist_arr=array("mh_name"=>I("mh_name"));
		$accute_arr=array('mh_isactive'=>I("mh_isactive"),'mh_type'=>I('mh_type'),"mh_id"=>I("mh_id"),
			"mh_email"=>I("mh_email"));
		$cookie_arr=array();	
		$con=searchCon($mist_arr,$accute_arr,$cookie_arr);
		parent::index($con);		
	}
	/**
	* 商户对账功能，即因为操作失误导致的账户金额错误，需要增加或者扣除	
	*/	
	public function transfer(){
		//调用对账单方法
		$result=createStatement(I("mh_id"),I("transfer_type"),I("transfer_money"),I("remark"));
		if($result)
			$this->success(L("action_success"));
		else
			$this->error(L("action_failed"));
	}
	
		/**
	*因为涉及到密码操作，重新添加方法
	*/
	public function addHandle(){
	try{
		$oop=M($this->model);
		$oop->create();
		$oop->mh_salt=makePass(20);//密码加盐值
		$oop->mh_pwd=md5(I("mh_pwd").$oop->mh_salt);
		$oop->mh_paypwd=md5(I("mh_paypwd").$oop->mh_salt);
		$oop->mh_token=makePass(25);//远程访问命令环
		if($oop->add())
			$this->success(L("add_success"));
		else
			$this->error(L("add_failed"));			
	}catch( \Exception $e){
		$this->error($e->getMessage());
		}
	}
		
	
	/**
	*因为涉及到密码操作，重新保存方法
	*/
	public function updateHandle(){
		//dump(I());EXIT;
		$oop=M($this->model);
		$oop->create();
		$oop->mh_salt=makePass(20);//密码加盐值
		if(I("mh_pwd")){
			$oop->mh_pwd=md5(I("mh_pwd").$oop->mh_salt);
		}
		if(I("mh_paypwd")){
			$oop->mh_paypwd=md5(I("mh_paypwd").$oop->mh_salt);
		}		
		if($oop->save())
			$this->success(L("update_success"));
		else
			$this->error(L("update_failed"));		
	}	
	
}